package com.leyou.item.controller;

import com.leyou.item.dto.CategoryDTO;
import com.leyou.item.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    // 根据父节点查询目录
    @GetMapping("/of/parent")
    public ResponseEntity<List<CategoryDTO>> selectCategotyByParId(@RequestParam(value = "pid") Long pid){
        return ResponseEntity.ok(categoryService.selectCategotyByParId(pid));
    }

    // 根据id的集合查询商品分类
    @GetMapping("/list")
    public ResponseEntity<List<CategoryDTO>> queryCategoryByIds(@RequestParam(value = "ids") List<Long> ids){
        return ResponseEntity.ok(categoryService.queryCategoryByIds(ids));
    }

    /**
     * 根据3级分类id，查询1~3级的分类
     * @param id
     * @return
     */
    @GetMapping("/levels")
    public ResponseEntity<List<CategoryDTO>> queryAllByCid3(@RequestParam("id") Long id){
        return ResponseEntity.ok(categoryService.queryAllByCid3(id));
    }
}
